package com.dotc.kotlinmvvmdemo.activity

import android.util.Log
import androidx.lifecycle.LifecycleObserver
import com.dotc.kotlinmvvmdemo.R
import com.dotc.kotlinmvvmdemo.base.BaseActivity
import com.dotc.kotlinmvvmdemo.databinding.ActivityStartBinding
import com.dotc.kotlinmvvmdemo.viewModel.StartViewModel
import kotlinx.android.synthetic.main.activity_start.*
import java.util.*

/**
 * 启动页面
 */
class StartActivity : BaseActivity<ActivityStartBinding, StartViewModel>()  {
    override fun modelClass(): Class<StartViewModel>? {
       return StartViewModel::class.java
    }

    override fun layout(): Int {
       return R.layout.activity_start
    }

    override fun initData() {
        //必须实现
        binding!!.viewModel=viewModel
        binding!!.lifecycleOwner=this
        //添加生命周期监听
        lifecycle.addObserver(viewModel as LifecycleObserver)
        binding!!.viewModel!!.context = this@StartActivity
    }

    override fun initObserve() {
        tv_click.setOnClickListener {
            test()
        }
    }



    private fun test() {
        //1、random 区间为[0.0,1.0）
        val random1 = Math.random()
        val rand  = Random()
        //[0~2]
        val a1 = rand.nextInt(3)
//        val a2 = rand.nextInt(10)
//        val a3 = rand.nextInt(10)
        Log.d("LUO", "===random1:${random1}")
        Log.d("LUO", "===a1:${a1}")
//        Log.d("LUO", "===a2:${a2}")
//        Log.d("LUO", "===a3:${a3}")
    }

}